Skip to content

Adapter shim for pollable incompatibility#600

Open
cceckman-at-fastly wants to merge 6 commits intomainfrom
cceckman/wit-dynamic-types
Open

Adapter shim for pollable incompatibility#600
cceckman-at-fastly wants to merge 6 commits intomainfrom
cceckman/wit-dynamic-types

Conversation

@cceckman-at-fastly
Copy link
Copy Markdown
Contributor

There are many handle types that, in WITX, are valid for async_io::select; among them are cache handles, cache replace handles, and HTTP cache handles. Each of these is backed with an async item (well, not HTTP cache handles, because they are not yet implemented in Viceroy) and can be waited on by select. The module ABI doesn't have strong notions of typing; these u32s are all in the same space.

In WIT, everything that can be waited on by async-io.select is an alias for the async-io.pollable handle type. The "component" version of Wasmtime checks these handles by type; not all u32s are the same.
But cache-entry, cache-replace-entry, and http-cache-entry are not such aliases; they are their own resources. If you pass one of these handles to async-io.select, you'll get an error.

We realized this leads to an incompatibility in adapted code. Code that works as a module (passing e.g. cache-entry to select) will break under the adapter, prior to this change.

This adds a shim layer to the adapter, tagging the three handle types above with extra bits in the high nybble. (These bits are reserved for purposes like this.) The adapter sets these bits per-type when producing the handle, and removes them before calling down in to the component ABI.

When these incompatible handles arrive at select (or is_ready), the adapter strips the type bits out to recover the handle, then uses it to call subscribe. subscribe returns the same handle, but tracked as a pollable, so it can then be fed in to the underlying ABI call.

These resources are pollable (`async_io::select`-able) in the WITX ABI,
but are not `async-io.pollable` in the WIT ABI.

To allow the adapter to shim the differences, add `subscribe` calls to
the WIT definitions.
@cceckman-at-fastly cceckman-at-fastly marked this pull request as ready for review April 14, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant